Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Algorithm to Solve Sudoku #356

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

abhishek2s
Copy link

Sudoku Solver

Follow the steps below to solve the problem:

Create a function that checks if the given matrix is valid sudoku or not. Keep Hashmap for the row, column and boxes. If any number has a frequency greater than 1 in the hashMap return false else return true; Create a recursive function that takes a grid and the current row and column index. Check some base cases.
If the index is at the end of the matrix, i.e. i=N-1 and j=N then check if the grid is safe or not, if safe print the grid and return true else return false. The other base case is when the value of column is N, i.e j = N, then move to next row, i.e. i++ and j = 0. If the current index is not assigned then fill the element from 1 to 9 and recur for all 9 cases with the index of next element, i.e. i, j+1. if the recursive call returns true then break the loop and return true. If the current index is assigned then call the recursive function with the index of the next element, i.e. i, j+1

Sudoku Solver


Follow the steps below to solve the problem:

Create a function that checks if the given matrix is valid sudoku or not. Keep Hashmap for the row, column and boxes. If any number has a frequency greater than 1 in the hashMap return false else return true;
Create a recursive function that takes a grid and the current row and column index.
Check some base cases. 
If the index is at the end of the matrix, i.e. i=N-1 and j=N then check if the grid is safe or not, if safe print the grid and return true else return false. 
The other base case is when the value of column is N, i.e j = N, then move to next row, i.e. i++ and j = 0.
If the current index is not assigned then fill the element from 1 to 9 and recur for all 9 cases with the index of next element, i.e. i, j+1. if the recursive call returns true then break the loop and return true.
If the current index is assigned then call the recursive function with the index of the next element, i.e. i, j+1
@abhishek2s
Copy link
Author

Follow the steps below to solve the problem:

Create a function that checks if the given matrix is valid sudoku or not. Keep Hashmap for the row, column and boxes. If any number has a frequency greater than 1 in the hashMap return false else return true;
Create a recursive function that takes a grid and the current row and column index.
Check some base cases.
If the index is at the end of the matrix, i.e. i=N-1 and j=N then check if the grid is safe or not, if safe print the grid and return true else return false.
The other base case is when the value of column is N, i.e j = N, then move to next row, i.e. i++ and j = 0.
If the current index is not assigned then fill the element from 1 to 9 and recur for all 9 cases with the index of next element, i.e. i, j+1. if the recursive call returns true then break the loop and return true.
If the current index is assigned then call the recursive function with the index of the next element, i.e. i, j+1

@abhishek2s abhishek2s closed this Oct 28, 2024
@abhishek2s abhishek2s reopened this Oct 28, 2024
@abhishek2s
Copy link
Author

verified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant